// pages/labeled/index.js

import { config } from "../../config/config";
import { Http } from "../../utils/http";
import { cache, promisic } from "../../utils/util";

Page({

  /**
   * 页面的初始数据
   */
  data: {
    code: '',
    scene: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: async function (options) {
    this.data.scene = options.scene;
    let result = await promisic(wx.login)({});
    this.setData({ code: result.code })

    let result_1 = await this.login();
    wx.setStorageSync('token', result_1.data.token)
    let result_2 = await this.label();
    wx.switchTab({
      url: '../register/index',
    })
  },

  /**
   *  登录 code 换 token 令牌
   */
  login: async function () {
    return await Http.request({
      url: 'wechat/index/login',
      data: { code: this.data.code },
    })
  },

  /**
   *  给会员打标签
   */
  label: async function () {
    return await Http.request({
      url: 'wechat/labeled/label',
      data: { id: this.data.scene },
    })
  },

})